vimfandomcom-20200223-history
Vim Tips Wiki:Featured Tip/2010
This is an archive of the Featured tip section on the Main Page for 2010. October 2010 Vim recognizes three file formats (unix, dos, mac) that determine what line ending characters (LF, CRLF, CR) are removed from each line when a file is read, or are added to each line when a file is written. A file format problem can display ^M characters, or can prevent scripts from running correctly. Our featured tip shows how to remove unwanted ^M characters, and explains how to convert from one file format to another. September 2010 Inserting a line break (newline) before or after each occurrence of specified text is easy. Our featured tip shows how to insert newlines using a simple substitute command. It also presents a small script that defines a command to make the job even easier. The script has an explanation that may be helpful for anyone wanting to see how Vim scripts work. August 2010 After pasting text, you may want to select that text so you can perform another operation. For example, you may want to indent the pasted text, or to perform a substitute within it. Our featured tip introduces the `[ and `] marks, and shows a simple mapping that allows you to select the text that was last changed, or the text that was just pasted. July 2010 Auto commenting is a handy feature, but it can be frustrating to press o to open a new line after a comment, then find the comment string inserted at the start of what you hoped would be a blank line. Our featured tip shows how to disable all auto commenting, or how to disable auto commenting only for //-style single-line comments in C/C++ files. June 2010 Syntax highlighting is a very useful feature of Vim, and there are many syntax files distributed with Vim to highlight keywords and more, for example, when editing a C or a Python program. But what if you need syntax highlighting for files you edit, yet there is no standard syntax file? Our featured tip is a tutorial showing how to create your own syntax files. May 2010 Have you ever wanted to insert the same text in the same position in multiple lines? That is easy with visual block mode: press I to have text inserted on each line in the selection. If the block visual selection used $ to select end-of-line, you can also press A to have the same text appended to each line. Our featured tip has the details. It also shows how to use the substitute command to insert or append text. April 2010 We all know what a tab page is – each tab holds a different file. Actually, Vim tabs are not like that. Instead, tab pages in Vim offer much more flexibility, and provide many features that are unavailable with standard editors. Our featured tip discusses ideas for how to make the most of tab pages in Vim: one tab can show windows for files you are currently working on, while other tabs display diffs, or x-ray or folded views, and more. March 2010 We have lots of good information on searching. One special requirement, when writing a program, is to limit the scope of what you search, such as by searching only within the current function, or only within the current code block. Our featured tip provides a script so you can easily search within a specified scope in program languages such as C and C++ that use braces ({...}) to delimit blocks. February 2010 On Windows systems, Vim can easily run an external program asynchronously without irritating "Press Enter" messages. You can run a GUI program with a command like :!start calc, and you can run a console-mode program with a command like :!start cmd /c myapp.exe & pause. Both examples run the program but immediately return to Vim, allowing you to continue editing while the invoked program runs. It is also possible use this method with Vim's features to run a program (like grep) for a long period without interrupting your editing, and notify Vim to take action (like loading the search results) when the program has finished. Our featured tip has the details. January 2010 You may need to view or edit a binary file. You can do that without leaving home because Vim provides the xxd utility to read a dump of a binary file, or to edit the dump then save it in binary form. Hex dump introduces xxd, and shows a handy feature to insert the hex equivalent of a binary file into C source code. Comments